$(function(){

        $(".form-horizontal").validate({
            rules: {
                name: {
                    required: true,
                },
                display_name: {
                    required: true,

                },
                password: {
                    required: true,
                    rangelength: [6,18],
                },
                password_confirmed: {
                    required: true,
                    rangelength: [6,18],
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
                type: {
                    required: true,
                },
                title:{
                    required: true,
                },
                description:{
                    required: true,
                },
                author:{
                    required:true,
                },
                tag_id:{
                    required:true,
                },
                first_pic:{
                    required:true,
                }
            
            },

            messages: {
                name: {
                    required: '*请填写名字',
                },
                type: {
                    required: '*请选择类型',
                },
                display_name:{
                    required: '*请填写名称',
                },
                email:{
                    required: '*请填写邮箱',
                    email:"请填写正确邮箱格式"
                },
                password:{
                    required:'请输入密码',
                    rangelength:'密码长度6-18位',
                },
                password_confirmed: {
                    required: "请输入确认密码",
                    rangelength:'密码长度6-18位',
                    equalTo: '输入密码不一致'
                },
                title:{
                    required: "*标题必须",
                },
                description:{
                    required: "*简介必须",
                },
                author:{
                    required:"作者必须",
                },
                tag_id:{
                    required:"*标签必须",
                },
                first_pic:{
                    required:"请上传封面图片",
                }


        },
        submitHandler: function(form) { //通过之后回调
            /*$(".btn").attr('disabled','disabled');
            layer.msg('请等待...', {
                icon: 16,
                shade: 0.01,
                time: 30000, //30s后自动关闭
            });*/
        var url=$(".style-form").attr('action');
        var param = $(".style-form").serialize(); 
        $.ajax({ 
            url : url, 
            type : "post", 
            dataType : "json", 
            data: param, 

            success : function(result) {
                    $("lable").text('')
                    if(result.status=='1') { 
                        location.href=result.data; 
                    } else { 
                        layer.msg('创建失败')
                    } 
            },
            error:function(e){
                var json=JSON.parse(e.responseText);
                    $("lable").text('')
                    for(var i in json){
                        
                        $(" .error_"+i+"").html("*"+json[i])
                    }
            },
            complete:function(e){
                setTimeout(function () {

                    layer.closeAll();

                }, 2000);

                $(".btn").removeAttr('disabled');
            },
            }); 
        }, 
        invalidHandler: function(form, validator) { //不通过回调 
           
        }, 
 
        });

});